package com.album.utils.down;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.album.utils.MyLog;
import com.album.utils.down.AsyncImageLoaders.ImageCallback;

public class MyImageAdapter extends BaseAdapter {  
    private Context mContext;  
    
    private List<String> imageList = new ArrayList<String>();  
    private AsyncImageLoaders imageLoader;
    public MyImageAdapter(Context c,List<String> imageList) {  
        mContext = c;  
        this.imageList = imageList;
        imageLoader = new AsyncImageLoaders();
    }  

    public int getCount() {  
        return imageList.size();  
    }  

    public Object getItem(int position) {  
        return imageList.get(position);  
    }  

    public long getItemId(int position) {  
        return position;  
    }  

    public View getView(int position, View convertView, ViewGroup parent) {    
        final ImageView imageView;           
        if (convertView == null) {      
            imageView=new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(70, 70));  
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);   
            convertView = imageView;   
            String url = imageList.get(position);
            Drawable drawable = imageLoader.loadDrawable(url, new ImageCallback() {  

                public void imageLoaded(Drawable imageDrawable, String imageUrl) {  
                   // MyLog.debug(getClass(), "===========imageDrawable =======:"+imageDrawable.getIntrinsicHeight());
                    if(imageDrawable!=null)
                    	imageView.setImageDrawable(imageDrawable);  
                }  
            });   
            imageView.setImageDrawable(drawable);
        }  
          
        return convertView;  
    }  
}  
